package com.iefgames.cs.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;

/**
 * 测试IE的iframe 中函数是否回调
 * */

public class TestComet extends HttpServlet {
	private static Log logger = LogFactory.getLog(TestComet.class);
	
	public void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		PrintWriter writer = response.getWriter();
		
		response.setContentType("text/plain; charset=utf-8");
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
		sb.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ");
		sb.append("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
		sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
		sb.append("<head>\n");
		sb.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n");
		sb.append("<script type='text/javascript'>");
		sb.append("alert('server recall');");
		sb.append("</script>");
		sb.append("</head>");
		sb.append("<body>");
		
		writer.println(sb.toString());
		writer.flush();
		
		
		logger.debug(sb.toString());
		
		Continuation continuation = ContinuationSupport.getContinuation(request, null);
		continuation.suspend(3 * 1000);
		
		writer.println("  ");
	}
}
